package com.ztw.yygh.cmn.Utils;

import com.ztw.yygh.cmn.service.HospitalService;
import com.ztw.yygh.cmn.service.HospitalSetService;
import com.ztw.yygh.common.exception.YyghException;
import com.ztw.yygh.common.result.ResultCodeEnum;
import com.ztw.yygh.common.utils.MD5;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class HospitalUtil {
    @Resource
    private HospitalSetService hospitalSetService;
    //签名验证
    public String CheckKey(Map<String, Object> parameterMap,String hoscode){
        //签名验证
        String hospSign = (String)parameterMap.get("sign");
        String signKey=hospitalSetService.getSignKey(hoscode);
        //md5加密
        String signKeyMd5= MD5.encrypt(signKey);
        //判断签名是否一致
        if(!hospSign.equals(signKeyMd5)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }
        return signKeyMd5;
    }
}
